package sum.book.auth.dto.user;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import sum.book.common.core.model.dto.BaseDTO;

import java.util.Collection;

/**
 * @Auther: ZhangGN
 * @Description: sss
 * @Date 2022/11/18 9:33
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CustomUser extends BaseDTO implements UserDetails {

    private static final long serialVersionUID = 1L;

    private String username;

    private String password;

    private boolean status;

    private Collection<GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList("admin");

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.status;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.status;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.status;
    }

    @Override
    public boolean isEnabled() {
        return this.status;
    }
}
